//
//  MyAppointTableViewController.m
//  demo
//
//  Created by maxine on 2016/11/11.
//  Copyright © 2016年 maxine. All rights reserved.
//

#import "MyAppointTableViewController.h"
#import "MyAppointTableViewCell.h"
#import "MyAppointTwoTableViewCell.h"

@interface MyAppointTableViewController ()
@property(nonatomic,strong) UIView *footerView;
@property(nonatomic,strong) UIView *headerView;

@end

@implementation MyAppointTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"贷款预约";
    self.tableView.tableHeaderView = self.headerView;
    self.tableView.tableFooterView = self.footerView;
    self.tableView.rowHeight = 57;
    
}

-(UIView *)footerView{
    
    if (_footerView == nil) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        _footerView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
    }
    UIButton *btn = [[UIButton alloc]init];
    btn.bounds = CGRectMake(0, 0, 140, 40);
    btn.backgroundColor = [UIColor colorWithRed:103/255.0 green:178/255.0 blue:69/255.0 alpha:1.0];
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    
    float centerX = _footerView.center.x;
    
    btn.center = CGPointMake(centerX, 50);
    
    if ([kUserInfo.userType isEqualToString:@"1"] || [kUserInfo.userType isEqualToString:@"2"] || [kUserInfo.userType isEqualToString:@"3"] ) {
        [_footerView addSubview:btn];
    }
    return _footerView;
    
}


/**
 提交贷款 
 */
- (void)submit{
    
     /*
     {
     "certNo":"430903902894839279",
     "custName":"aaa",
     "custSource":"7",
     "custSourceName":"其他",
     "loanUse":"1",
     "loanUseVal":"日常生活消费",
     "mobile":"15200351221",
     "orderTime":"2017-01-18 22:37",
     "prodId":"1001",
     "prodName":"微英借",
     "sessionId":"809fc5eb-723f-4502-a614-10f2e7adceff",
     "sex":"F",
     "sexVal":"女",
     "smId":"e6b6d628650b404da4502568794621ff",
     "smMobile":"15200351110",
     "smName":"文星",
     "teamId":"1094041588254ff2a4f555b1d94ecaa6",
     "teamName":"康庄联社",
     "tmId":"8b86d75fd4e44dee9a7f7bddf8314e59",
     "tmName":"杜小康"
     }
     */

    
    
    
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    
    parameters[@"certNo"] = kUserInfo.idCard;
    parameters[@"custName"] = kUserInfo.userName;
    
    parameters[@"mobile"] = kUserInfo.tel;
    parameters[@"orderTime"] = [NSDate new].toTimeStamp;
    
    parameters[@"custSource"] = @"7";
    parameters[@"custSourceName"] = @"其他";
    
    parameters[@"prodId"] = self.model.prodId;
    parameters[@"prodName"] = self.model.prodName;
    parameters[@"sessionId"] = [[NSUserDefaults standardUserDefaults] valueForKey:@"sessionId_key"];
    
    //性别暂时固定  -- 实际是要根据当前用户的性别来取
    parameters[@"sex"] = @"F";
    parameters[@"sexVal"] = @"女";
    
    //借款用途
    parameters[@"loanUse"] = @"2";
    parameters[@"loanUseVal"] = @"其他";
    
    if (kUserInfo.busRepList.count) {        
        parameters[@"smId"] = kUserInfo.busRepList[0].userId;
        parameters[@"smMobile"] = kUserInfo.busRepList[0].tel;
        parameters[@"smName"] = kUserInfo.busRepList[0].userName;
    }

    parameters[@"teamId"] = @"1";
    parameters[@"teamName"] = @"1";
    parameters[@"tmId"] = @"1";
    parameters[@"tmName"] = @"1";
    
    if (kUserInfo.busRepList[0].userId) {
        parameters[@"smId"] = kUserInfo.busRepList[0].userId;
    }
    parameters[@"certNo"] = kUserInfo.idCard;
    
    WeakSelf(Wself);
    HUDLoading(@"请稍候...");
    [[ZXHTTPManager sharedManagerNOCer]dkYuyueWithParam:parameters completed:^(NSDictionary *jsonDict, NSError *error) {
        HUDStop;
        if (error) {
            NSLog(@"error = %@",error);
            HUDStop;

            HUDNormal(@"请检查网络或稍后重试!");
            return ;
        }
        if ([jsonDict[@"statusCode"] isEqualToString:@"SUCCESS"]) {
            
            HUDNormal(@"预约成功!");
            [NSThread sleepForTimeInterval:2.0];
            [Wself.navigationController popViewControllerAnimated:YES];
        }
    }];
}


#pragma - mark 贷款管理 暂停

-(UIView *)headerView{
    if (_headerView == nil) {
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 8)];
        _headerView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
    }
    return _headerView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyAppointTableViewCell *cell = [MyAppointTableViewCell cellWithTableView:tableView];
    MyAppointTwoTableViewCell *cellt = [MyAppointTwoTableViewCell cellWithTableView:tableView];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cellt.selectionStyle = UITableViewCellSelectionStyleNone;
    
    switch (indexPath.row) {
        case 0:
            cell.titleLabel.text = @"产品名称";
            cell.detailLabel.text = self.model.prodName;
            break;
        case 1:
            cell.titleLabel.text = @"客户名称";
            cell.detailLabel.text = kUserDetailInfo.custName;
            break;
        case 2:
            cell.titleLabel.text = @"手机";
            cell.detailLabel.text = kUserDetailInfo.tel;
            
            break;
        case 3:
            cell.titleLabel.text = @"身份证号码";
            cell.detailLabel.text = kUserDetailInfo.idCard;
            
            break;
        case 4:
            cell.titleLabel.text = @"性别";
            if ([kUserInfo.gender isEqualToString:@"F"]) {
                cell.detailLabel.text = @"女";
            }else{
                cell.detailLabel.text = @"男";
            }
            break;
        case 5:
            
            cellt.titleLabel.text = @"借款用途";
            return cellt;
            
            break;
            
        default:
            break;
    }
    
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    switch (indexPath.row) {
            
        case 5:
        {
            MyAppointTwoTableViewCell *cellt = [tableView cellForRowAtIndexPath:indexPath];
            [cellt.produceTf becomeFirstResponder];
            
        }
            break;
            
        default:
            break;
    }
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
